#!/usr/bin/lua


ngx.header.content_type = "application/json"
ngx.header['Content-Type'] = "application/json;charset=UTF-8"

local cmd = ngx.req.get_uri_args()['cmd']

if not cmd then
    package.path = "/web/muggle/Api/package/?.lua"
    local Crash= require("error/crash")
    ngx.say(Crash:push("缺少接口参数"))
    return -1
end

-- 接口的push方法应返回json格式字符串
local file = io.open("/web/muggle/Api/response/"..cmd.."/main.lua")
if not file then
    package.path = "/web/muggle/Api/package/?.lua"
    local Crash= require("error/crash")
    ngx.say(Crash:push("请求的接口不存在"))
    return -1
end
io.close("/web/muggle/Api/response/"..cmd.."/main.lua")

package.path = "/web/muggle/Api/response/?.lua"
local app =  require(cmd .. "/main")
ngx.say(app.push())